 package com.ghbank.rdws.codeservice;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Component;

import com.ghbank.rdws.biz.service.RdwsService;

/**
 * 应用健康检查
 * @author liuxudong
 * @date 2019年3月25日
 */
@Component
public class CodeServiceHealthIndicator implements HealthIndicator {
    
    @Autowired
    private RdwsService rdwsService;
    
    @Override
    public Health health() {
      int errorCode = check();
      if (errorCode != 0) {
        return Health.down().withDetail("Error Code", errorCode).build();
      }
      return Health.up().build();
    }

    private int check() {
      PageRequest pageable = PageRequest.of(0, 1);
      rdwsService.queryDataSourceConfig(pageable);
      return 0;
    }
}
